<%= javascript_include_tag "prototype" %>
<%= javascript_include_tag "util" %>
<%= javascript_include_tag "calendar" %>
<script type="text/javascript">
        function checkNum(flag, msg_id, obj_name, msg_text){
                if (flag) {
                        if ($(obj_name).value != "" && ! digCheck($(obj_name).value))
                        {
                                $(msg_id).innerText = msg_text;
                                $(msg_id).style.display = "block";
                                return false;
                        }
                        else return true;
                }
                else {
                        $(msg_id).style.display = "none";
                }
        }

function checkDate()
{
        if ( checkNum(true,'id_serial','id_paper_serial','订单号输入错误') )
                frmSalePaper.submit();
}
function showAgentWindow(id)
{
        window.open("/other_org/agent_info/"+id,"_blank","height=450,width=500,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}

function showPaperWindow(id)
{
        window.open("/sale/show_print_sale_paper/"+id,"_blank","height=450,width=750,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
</script>
<h1>订单管理 - <span id="secondHeading">订单支付管理</span></h1>
<% if @flash[:notice] -%>
<div id="notice"><%= @flash[:notice] %></div>
<% end -%>
<form id="input-form" name="frmSalePaper" action="/sale/charge_sale_paper" method="post">
<table id="INPUT_TABLE" style="margin-left:30px;">
	<tr>
                <td width="15%">
                订&nbsp;单&nbsp;号：
                                </td>
                <td>
                <input id="id_paper_serial" type="text" name="paper_serial" size="20" maxlength="20" onfocus ="checkNum(false,'id_serial')" onblur="checkNum(true,'id_serial',this.id,'订单号输入错误')"/>&nbsp;已支付<input type="checkbox" name="charged" value="yes"> <div class="redNsg" id="id_serial" style="display:none;"></div>
                </td>
                <tr>
                <td>
        起始时间：
        </td>
        <td>
        <!-- <input id="beginDate" type="text" name="from"> -->
        <script language=javascript>
        var beignDate=new dateSelector();
        beignDate.inputID='beginDate';
        beignDate.inputName='from';
        beignDate.display();
        </script>
        </td>
        </tr>
        <tr>
        <td>
        结束时间：
        </td>
        <td>
        <!--<input id="endDate" type="text" name="to">-->
        <script language=javascript>
        var endDate=new dateSelector();
        endDate.inputID='endDate';
        endDate.inputName='to';
        endDate.display();
        </script>
        </td>
	</tr>
	<tr>
                <td colspan="2" align="right">
        <input  type="button" value="查询" class="sub" onclick="checkDate()">
                </td>
	</tr>
</table>
</form>
<br/>
<TABLE border="0" id="LIST_TB">
	<TR id="LIST_TB_TITLE">
      <td nowrap>编号</td>
      <td nowrap>销售</td>
      <td nowrap>购买方</td>
      <td>状态</td>
      <td>销售日期</td>
      <td>支付</td>
      <td>相关操作</td>
    </tr>
    <%@sale_papers.each do |paper|%>
    <TR id="LIST_TB_CONTENT1">
      <td><a href="javascript:showPaperWindow(<%=paper.id%>)"><%=paper.id%></a></td>
      <td><%=paper.employee.name%></td>
      <td><a href="javascript:showAgentWindow(<%=paper.agent.id%>)"><%=paper.agent.name%></a></td>
      <td><%='<font color="green">已通过</font>' if paper.papertype.eql? 'OK'%> <%='未审批' if paper.papertype.eql? 'UN'%> <%= '<font color="red">未通过</font>' if paper.papertype.eql? 'NO'%> <%='已停用' if paper.papertype.eql? 'CA'%><%='已补齐' if paper.papertype.eql? 'GO'%><%='已完成' if paper.papertype.eql? 'NDFD'%><%='已退货' if paper.papertype.eql? 'RE'%>
      <td><%=paper.sale_date_at%></td>
      <td><%='<font color="red">未支付</font>' if paper.charge.eql? 'no'%><%='<font color="green">已支付</font>' if paper.charge.eql? 'yes'%></td>
      <td><%if paper.charge.eql? 'no'%><a href="/sale/charge_sale_paper?id=<%=paper.id%>&method=charge" onclick="return confirm('你确定支付该订单吗?');">支付该订单</a><%elsif paper.charge.eql? 'yes'%><a href="/sale/charge_sale_paper?id=<%=paper.id%>&method=uncharge" onclick="return confirm('你确定取消支付该订单吗?');">取消支付</a><%end%></td>
    </tr>
    <%end%>
</table>
<table>
        <tr>
                <td>
                        <input type="button" value="打印当前页" class="sub" onclick="openPrintWindow('LIST_TB')"/>
                        <input type="button" value="导出当前数据" class="sub" onclick="CellAreaExcel('LIST_TB')"/>
                </td>
        </tr>
</table>
